
//
//  StepTableViewCell.m
//  Cooking
//
//  Created by ZhiPeng.Y on 15/9/2.
//  Copyright (c) 2015年 ZP.Y. All rights reserved.
//

#import "StepTableViewCell.h"
#import "AppMacro.h"
#import "StepModel.h"
#import "UIImageView+WebCache.h"
@interface StepTableViewCell ()

@property (retain, nonatomic) UIImageView *backGroundImage;
@property (retain, nonatomic) UIImageView *foodImage;
@property (retain, nonatomic) UILabel     *numberLabel;
@property (retain, nonatomic) UILabel     *stepLabel;

@end
@implementation StepTableViewCell

- (void)dealloc {
    [_backGroundImage release];
    [_foodImage release];
    [_numberLabel release];
    [_stepLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {
    self.backGroundImage = [[UIImageView alloc] init];
    //    _backGroundImage.backgroundColor = [UIColor greenColor];
    _backGroundImage.image = [self imageWithName:@"backGround" type:@"png"];
    [self.contentView addSubview:_backGroundImage];
    [_backGroundImage release];
    
    self.foodImage = [[UIImageView alloc] init];
//    _foodImage.backgroundColor = [UIColor purpleColor];
    [_backGroundImage addSubview:_foodImage];
    [_foodImage release];
    
    self.numberLabel = [[UILabel alloc] init];
    _numberLabel.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:240 / 255.0 blue:215 / 255.0 alpha:1];
    _numberLabel.layer.cornerRadius = 10;
    _numberLabel.layer.masksToBounds = YES;
    _numberLabel.font = [UIFont systemFontOfSize:12];
    _numberLabel.textAlignment = NSTextAlignmentCenter;
    [_backGroundImage addSubview:_numberLabel];
    [_numberLabel release];
    
    self.stepLabel = [[UILabel alloc] init];
//    _stepLabel.backgroundColor = [UIColor grayColor];
    _stepLabel.numberOfLines = 0;
    _stepLabel.font = [UIFont systemFontOfSize:15];
    [_backGroundImage addSubview:_stepLabel];
    [_stepLabel release];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _backGroundImage.frame = CGRectMake(30, 10, WIDTH - 60, HEIGHT / 2.7);
    _foodImage.frame = CGRectMake(12, 12, _backGroundImage.frame.size.width - 24, _backGroundImage.frame.size.height - 80);
    _numberLabel.frame = CGRectMake(8, _foodImage.frame.origin.y + _foodImage.frame.size.height + 5, 20, 20);
    _stepLabel.frame = CGRectMake(_numberLabel.frame.origin.x + _numberLabel.frame.size.width + 5, _foodImage.frame.origin.y + _foodImage.frame.size.height + 5, _backGroundImage.frame.size.width - 24 - _numberLabel.frame.size.width, 35);
        [_stepLabel sizeToFit];

    
}

- (UIImage *)imageWithName:(NSString *)imageName type:(NSString *)imageType {
    NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:imageType];
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    return image;
}

- (void)sendValueWithModel:(StepModel *)stepModel {
    [_foodImage sd_setImageWithURL:[NSURL URLWithString:stepModel.imagePath] placeholderImage:[UIImage imageNamed:@"zhanwei_02.png"]];
    _numberLabel.text = stepModel.order_id;
    _stepLabel.text = stepModel.describe;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
